//an object is not considered constructed until its constructor has completed.
//Then and only then will 'Stack Unwinding" cal the destructor for the object.

//~A() won't be called!!!
//~B() will be called
#include <iostream>
using namespace std;
class B{
  int bb;
public:
  B(){cout<<"B()"<<endl;}
  ~B(){cout<<"~B()"<<endl;}
};
class C{
  int cc;
public:
  C(){cout<<"C()"<<endl;}
  ~C(){cout<<"~C()"<<endl;}
};
class A :public B{
  int aa;
  C c;
public:
  A(){cout<<"A()"<<endl;throw 1212;cout<<"after thrown in A()"<<endl;}
  ~A(){cout<<"~A()"<<endl;}
};

void foo()
{
  A a;
  try {
    int i = 12;
    throw i;
  }
  catch(int j){
    cout<<"caught in foo()"<<endl;
    cout<<"j ="<<j<<endl;
    throw j;
  }

  cout<<"out of try-catch in foo()"<<endl;
}

int main()
{
  try{
    foo();
  }
  catch(...) {
    cout<<"caught in main()"<<endl;
  }
  cout<<"out of try-catch in main()"<<endl;
  return 0;
}
    
